<?php
/**
 * 视频的评论
 * @author  zhanghui
 * @create_date 2008-02-27
 */

class VideoComment{
    function __construct(){}
    
    function __destruct(){}
    
    /* 增加评论  
     * @param : $arr_input - baby_id,postid,comment_id,comment,writer_id,writer_name,ip_address,create_date
     */
    public function addComment($conn,$arr_input){
        $str_query = "insert into";
        $str_query .= " baby_diary_comment";
        $str_query .= " set";
        $str_query .= " baby_id={$arr_input['baby_id']}";
        $str_query .= ",postid={$arr_input['postid']}";
        $str_query .= ",comment='{$arr_input['comment']}'";
        $str_query .= ",writer_id={$arr_input['writer_id']}";
        $str_query .= ",writer_name='{$arr_input['writer_name']}'";
        $str_query .= ",ip_address='{$arr_input['ip_address']}'";
        $str_query .= ",create_date='".$conn->getCurrentTime()."'";
 
        $conn->executeQuery($str_query);
    }
    
    /* 获取评论
     * @param : $arr_input - baby_id,postid,comment_id,comment,writer_id,writer_name,ip_address,create_date
     * @return: $arr_output
     *          baby_id,           [0]<br>
     *          postid,            [1]<br>
     *          comment_id,        [2]<br>
     *          comment,           [3]<br>
     *          writer_id,         [4]<br>
     *          writer_name,       [5]<br>
     *          ip_address,        [6]<br>
     *          create_date,       [7]<br>
     */
     public function getCommentList($conn,$arr_input,$limit = null){
    	$str_query = "select";
        $str_query .= " baby_id";
    	$str_query .= " ,postid";
   		$str_query .= " ,comment_id";
   		$str_query .= " ,comment";
   		$str_query .= " ,writer_id";
   		$str_query .= " ,writer_name";
   		$str_query .= " ,ip_address";     		
   		$str_query .= " ,create_date";
    	$str_query .=" from";
    	$str_query .=" baby_diary_comment";
    	$str_query .=" where";
    	$str_query .=" baby_id={$arr_input['baby_id']}";
    	$str_query .=" and postid={$arr_input['postid']}";
    	
    	if (isset($arr_input['comment_id'])) {
    		$str_query .=" and comment_id={$arr_input['comment_id']}"; 
    	}   	
    	if (isset($arr_input['orderby'])) {
    		$str_query .= " order by {$arr_input['orderby']}";
    	}
    	if ($limit != null){
    		$str_query .= " {$limit}";
    	}
    	$arr_output = $conn->selectQuery($str_query);
    	return $arr_output;
    }
    
    /*删除评论
     * @param : $arr_input - baby_id,folderid,postid,comment_id,comment,writer_id,writer_name,ip_address,create_date
     */
    public function deleteComment($conn,$arr_input){
    	$str_query = "delete from";
    	$str_query .= " bady_diary_comment";
    	$str_query .= " where";
    	$str_query .= " baby_id={$arr_input['baby_id']}";
        $str_query .= " and postid={$arr_input['postid']}";
        
    	if(isset($arr_input['comment_id'])){
    		$str_query .= " and comment_id ={$arr_input['comment_id']}";
    		$conn->executeQuery($str_query); 
    	
    	   $obj_VideoCnt = new VideoCnt();
           $arr_input['comment_cnt'] = -1;
    	   $obj_VideoCnt->updateCommentCnt($conn,$arr_input);   
    	}else{
    		$conn->executeQuery($str_query);
    		$obj_VideoCnt = new VideoCnt();
    		$obj_VideoCnt->deleteVideoCnt($conn,$arr_input);
    	} 		
    } 
          
}
?>